home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / LgcyPlus / disk2 / SYSTHAND._ / SYSTHAND.
Encoding:
Text File  |  2001-03-02  |  6.3 KB  |  171 lines

  1. 10    ! **************************************************************
  2. 20    ! Example: SYSTEM Widget Event Handler
  3. 30    !
  4. 40    ! This program shows how to handle queued events from a SYSTEM
  5. 50    ! widget.  A SYSTEM widget has an attribute named *QUEUE EVENTS,
  6. 60    ! which is normally turned off. In that state, the SYSTEM widget
  7. 70    ! will not queue up events -- you get one and all later ones are lost.
  8. 80    !
  9. 90    ! If you set *QUEUE EVENTS to 1, however, events are queued --
  10. 100   ! which leads to the problem of sorting out events from each other.
  11. 110   !
  12. 120   ! This program shows how this is done by queueing up events from
  13. 130   ! three SLIDER widgets contained in a SYSTEM widget. When you
  14. 140   ! tell the program to flush the queue, it lists the queued events
  15. 150   ! by source SLIDER and event type and gives the number of
  16. 160   ! events in each category.
  17. 170   !
  18. 180   ! This is a somewhat contrived program in that the level of
  19. 190   ! event handling demonstrated here is overkill.  Under normal
  20. 200   ! circumstances, event queueing should not be a concern. In
  21. 210   ! fact, this program has to go to considerable lengths to force
  22. 220   ! the events to be queued -- by raising the SYSTEM PRIORITY
  23. 230   ! to mask out the SLIDER events, and only lowering it when
  24. 240   ! it polls a TOGGLEBUTTON and gets back a 1.
  25. 250   !
  26. 260   ! The SYSTEM MENU event that allows you to exit the program
  27. 270   ! is set to a high priority level, so you can exit the program at
  28. 280   ! any time.
  29. 290   !
  30. 300   ! **************************************************************
  31. 310   !
  32. 320   CLEAR SCREEN
  33. 330   INTEGER N                    ! General-purpose variable
  34. 340   INTEGER D(1:4),Dw,Dh,Iw,Ih   ! Variables for display handling
  35. 350   INTEGER Px,Py,Pw,Ph          ! PANEL parameters
  36. 360   INTEGER Gx,Gy                ! Internal layout gaps
  37. 370   INTEGER Nc,R,Sx,Sy,Sw,Sh     ! Parameters for SYSTEM widget SLIDERS
  38. 380   INTEGER Prx,Pry,Prw,Prh      ! Parameters for PRINTER widget
  39. 390   INTEGER Tx,Ty,Th,Tw          ! Parameters for TOGGLE BUTTON
  40. 400   DIM Ev$(1:2)[50],S$[50]      ! Return event source - GP string
  41. 410   !
  42. 420   ! Set up a PANEL in the center of the printing display and put
  43. 430   ! a SYSTEM MENU on it so you can quit the program.
  44. 440   !
  45. 450   STATUS CRT,13;N
  46. 460   GESCAPE CRT,3;D(*)
  47. 470   Dw=D(3)-D(1)
  48. 480   Dh=(D(4)-D(2))*((N-7)/N)
  49. 490   !
  50. 500   Pw=Dw*.99
  51. 510   Ph=Dh*.99
  52. 520   Px=(Dw-Pw)/2
  53. 530   Py=(Dh-Ph)/2
  54. 540   !
  55. 550   ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
  56. 560   CONTROL @Main;SET ("X":Px+100,"Y":Py+50,"WIDTH":.75*Pw,"HEIGHT":.75*Ph)
  57. 570   CONTROL @Main;SET ("SYSTEM MENU":"Quit")
  58. 580   CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
  59. 590   CONTROL @Main;SET ("TITLE":" Example: SYSTEM Widget Event Handling")
  60. 600   STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
  61. 610   !
  62. 620   ! Create a SYSTEM widget as a child of the main PANEL, populate
  63. 630   ! with SLIDER widgets.
  64. 640   !
  65. 650   ASSIGN @Sys TO WIDGET "SYSTEM";PARENT @Main
  66. 660   !
  67. 670   Gx=Iw*.01
  68. 680   Gy=Gx
  69. 690   !
  70. 700   Nc=3
  71. 710   Sh=Ih*.85
  72. 720   Sw=Iw*.11
  73. 730   Sy=Gy
  74. 740   !
  75. 750   FOR C=1 TO Nc
  76. 760     Sx=(C-1)*Sw+Gy
  77. 770     S$="S"&VAL$(C)
  78. 780     CONTROL @Sys;SET ("*NAME":S$,"*CREATE":"SLIDER")
  79. 790     CONTROL @Sys;SET ("X":Sx,"Y":Sy,"WIDTH":Sw,"HEIGHT":Sh)
  80. 800   NEXT C
  81. 810   !
  82. 820   ! Set up a TOGGLEBUTTON to indicate when to trap events
  83. 830   !
  84. 840   Th=Ih-(Sh+3*Gy)
  85. 850   Tw=Iw/2
  86. 860   Tx=Gx+(3*Sw-Tw)/2
  87. 870   Ty=Ih-(Th+Gy)
  88. 880   ASSIGN @Toggle TO WIDGET "TOGGLEBUTTON";PARENT @Main
  89. 890   CONTROL @Toggle;SET ("X":Tx+50,"Y":Ty,"WIDTH":Tw,"HEIGHT":Th)
  90. 900   CONTROL @Toggle;SET ("LABEL":"Flush Queue")
  91. 910   !
  92. 920   ! Set up a PRINTER widget on the main PANEL (not as part of
  93. 930   ! the SYSTEM widget) to log event handling
  94. 940   !
  95. 950   Prw=Iw-(3*Sw+3*Gy)
  96. 960   Prh=Ih-2*Gy
  97. 970   Prx=Iw-(Prw+Gy)
  98. 980   Pry=Gy
  99. 990   !
  100. 1000  ASSIGN @Prn TO WIDGET "PRINTER";PARENT @Main
  101. 1010  CONTROL @Prn;SET ("X":Prx,"Y":Pry,"WIDTH":Prw,"HEIGHT":Prh)
  102. 1020  !
  103. 1030  ! Set up events to trap the SLIDERs in the SYSTEM widget, and
  104. 1040  ! set up a high priority trap on the "Quit" button in the SYSTEM
  105. 1050  ! MENU
  106. 1060  !
  107. 1070  CONTROL @Sys;SET ("*QUEUE EVENTS":1)
  108. 1080  ON EVENT @Sys,"CHANGED" GOSUB Handler
  109. 1090  ON EVENT @Sys,"DONE" GOSUB Handler
  110. 1100  ON EVENT @Main,"SYSTEM MENU",15 GOTO Finis
  111. 1110  !
  112. 1120  ! Set event to quit on SYSTEM MENU, make whole thing visible, loop
  113. 1130  ! -- mask out normal events until user toggles the TOGGLEBUTTON
  114. 1140  !
  115. 1150  CONTROL @Main;SET ("VISIBLE":1)
  116. 1160  LOOP
  117. 1170    SYSTEM PRIORITY 1
  118. 1180    REPEAT
  119. 1190      STATUS @Toggle;RETURN ("VALUE":N)
  120. 1200    UNTIL (N<>0)
  121. 1210    CONTROL @Toggle;SET ("VALUE":0)
  122. 1220    CONTROL @Prn;SET ("TEXT":"")
  123. 1230    SYSTEM PRIORITY 0
  124. 1240  END LOOP
  125. 1250  !
  126. 1260  ! This event handler confirms SLIDER events by printing out the
  127. 1270  ! event and its source. It performs a loop, checking to see
  128. 1280  ! if there are events in the queue. If there are, it reads the
  129. 1290  ! first event in the queue and flushes all the same events.
  130. 1300  ! (You could also read them out if you like.) It continues
  131. 1310  ! doing this until it cleans out the queue.
  132. 1320  !
  133. 1330 Handler: !
  134. 1340  LOOP
  135. 1350  !
  136. 1360  ! Determine total number of events in queue
  137. 1370  !
  138. 1380    CONTROL @Sys;SET ("*EVENT WIDGET FILTER":"")
  139. 1390    CONTROL @Sys;SET ("*EVENT NAME FILTER":"")
  140. 1400    STATUS @Sys;RETURN ("*QUEUED EVENTS":N)
  141. 1410  !
  142. 1420  EXIT IF N=0
  143. 1430  !
  144. 1440    S$="> Total events in queue:  "&VAL$(N)
  145. 1450    CONTROL @Prn;SET ("APPEND TEXT":S$)
  146. 1460    !
  147. 1470    ! Get ID of first source in queue.
  148. 1480    !
  149. 1490    STATUS @Sys;RETURN ("*QUEUED EVENT":Ev$(*))
  150. 1500    !
  151. 1510    ! Determine how many of the same events are in the
  152. 1520    ! queue and then flush them
  153. 1530    !
  154. 1540    CONTROL @Sys;SET ("*EVENT WIDGET FILTER":Ev$(1))
  155. 1550    CONTROL @Sys;SET ("*EVENT NAME FILTER":Ev$(2))
  156. 1560    STATUS @Sys;RETURN ("*FLUSH QUEUED EVENTS":N)
  157. 1570    !
  158. 1580    S$="  Widget / Event / Total: "
  159. 1590    S$=S$&Ev$(1)&" / "&Ev$(2)&" / "&VAL$(N+1)
  160. 1600    CONTROL @Prn;SET ("APPEND TEXT":S$)
  161. 1610    !
  162. 1620    CONTROL @Prn;SET ("APPEND TEXT":"")
  163. 1630    !
  164. 1640  END LOOP
  165. 1650  RETURN
  166. 1660  !
  167. 1670 Finis: !
  168. 1680  ASSIGN @Main TO *   ! Delete PANEL widget
  169. 1690  CLEAR SCREEN
  170. 1700  END
  171.